#include<bits/stdc++.h>
using namespace std;
#define int unsigned
int n,m;
int ax[500010],qzh[500010];
int tot=0,gta[500010],gtb[500010],nxt[500010],head[500010];
int ttot=0,ggta[500010],ggtb[500010],ggtc[500010],nnxt[500010],hhead[500010];
int aa[500010],bb[500010];
int wz[500010],ans[500010];
int qa[500010],qqa[500010],qb[500010],qbw[500010],qqw[500010],qans[500010];
signed main()
{
	freopen("c.in","r",stdin);
    freopen("c.out","w",stdout);
	// freopen("./_data_/c4-41.in","r",stdin);
	cin>>n>>m;
	for(int i=1; i<=m; ++i)
	{
		int a,b,c,d; cin>>a>>b>>c>>d;
		ax[a]=max(ax[a],b);
		gta[++tot]=a,gtb[tot]=b,nxt[tot]=head[c],head[c]=tot;
		ggta[++ttot]=a,ggtb[ttot]=b,ggtc[ttot]=c,nnxt[ttot]=hhead[d],hhead[d]=ttot;
	}
	for(int i=n-1; i>=1; --i) ax[i]=max(ax[i],ax[i+1]);
	for(int i=1; i<=n; ++i) qzh[i]=qzh[i-1]+ax[i];
	int axa=0,axb=0,wwz=n;
	for(int i=n; i>=1; --i)
	{
		for(int j=head[i]; j!=0; j=nxt[j]) axa=max(axa,gta[j]),axb=max(axb,gtb[j]);
		aa[i]=axa,bb[i]=axb;
		ans[i]=(axa+axb)*n-axa*axb;
		while(wwz>=1 && ax[wwz]<=axb) --wwz;
		wz[i]=wwz;
		if(axb<ax[axa+1]) ans[i]+=qzh[wwz]-qzh[axa]-axb*(wwz-axa);
	}
	for(int i=1; i<=n; ++i)
	{
		qa[i]=qa[i-1]+aa[i],qqa[i]=qqa[i-1]+qzh[aa[i]];
		qb[i]=qb[i-1]+bb[i],qbw[i]=qbw[i-1]+bb[i]*wz[i],qqw[i]=qqw[i-1]+qzh[wz[i]];
		qans[i]=qans[i-1]+ans[i];
	}
	axa=0,axb=0; int axc=0,aans=0;
	int wzaxb=n,wwza=n,wwzb=n,wwz1=1,wwz2=1;
	for(int i=n; i>=1; --i)
	{
		for(int j=hhead[i]; j!=0; j=nnxt[j]) axa=max(axa,ggta[j]),axb=max(axb,ggtb[j]),axc=max(axc,ggtc[j]);
		aans+=axc*n*n;
		int nowans=(axa+axb)*n-axa*axb;
		while(wzaxb>=1 && ax[wzaxb]<=axb) --wzaxb;
		if(axb<ax[axa+1]) nowans+=qzh[wzaxb]-qzh[axa]-axb*(wzaxb-axa);
		while(wwza>=1 && aa[wwza]<=axa) --wwza;
		int wza=max(wwza,axc);
		while(wwzb>=1 && bb[wwzb]<=axb) --wwzb;
		int wzb=max(wwzb,axc);
		aans+=qans[min(wza,wzb)]-qans[axc]+(n-max(wza,wzb))*nowans;
		if(wza<=wzb)
		{
			aans+=(qb[wzb]-qb[wza])*(n-axa)+axa*n*(wzb-wza);
			while(wwz1<=n && bb[wwz1]>=ax[axa+1]) ++wwz1;
			int wwz=max(wza+1,min(wwz1,wzb+1));
			aans+=qqw[wzb]-qqw[wwz-1]-qzh[axa]*(wzb-wwz+1)
			-(qbw[wzb]-qbw[wwz-1])+(qb[wzb]-qb[wwz-1])*axa;
		}
		else
		{
			aans+=(qa[wza]-qa[wzb])*(n-axb)+axb*n*(wza-wzb);
			while(wwz2<=n && ax[aa[wwz2]+1]<=axb) ++wwz2;
			int wwz=max(wzb+1,min(wwz2,wza+1));
			aans+=qzh[wzaxb]*(wza-wwz+1)-(qqa[wza]-qqa[wwz-1])
			-axb*wzaxb*(wza-wwz+1)+axb*(qa[wza]-qa[wwz-1]);
		}
	}
	cout<<n*n*n*n-aans;
	return 0;
}
